package com.swh;

import com.swh.dao.UserDao;
import com.swh.entity.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

/**
 * @Author: swh
 * @Description:
 * @Date: 2020/12/9 17:37
 * @Version: 1.0
 */

public class Demo2 {
    public static void main(String[] args) throws IOException {
        InputStream is = Resources.getResourceAsStream("SqlMapConfig.xml");
        SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();

        SqlSessionFactory factory = builder.build(is);

        SqlSession session = factory.openSession(true);

        UserDao userDao = session.getMapper(UserDao.class);

        User findById = userDao.findById(2);

        System.out.println(findById);

        is.close();
        session.close();
    }
}
